/// @tags: SegmentTree
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 1e5 + 5;

int n;
int val[maxn * 4], lst[maxn], a[maxn];
bool able[maxn];

void update(int u, int l, int r, int pos, int v) {
  if (l == r) return (void)(val[u] = v);
  int mid = (l + r) / 2;
  if (pos <= mid)
    update(u << 1, l, mid, pos, v);
  else
    update(u << 1 | 1, mid + 1, r, pos, v);
  val[u] = std::min(val[u << 1], val[u << 1 | 1]);
}

int query(int u, int l, int r, int L, int R) {
  if (L <= l && r <= R) return val[u];
  int mid = (l + r) / 2, res = 0x7fffffff;
  if (L <= mid) res = std::min(res, query(u << 1, l, mid, L, R));
  if (mid < R) res = std::min(res, query(u << 1 | 1, mid + 1, r, L, R));
  return res;
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    if (a[i] != 1) able[1] = true;
    if (a[i] > 1 && query(1, 1, n, 1, a[i] - 1) > lst[a[i]]) able[a[i]] = true;
    lst[a[i]] = i;
    update(1, 1, n, a[i], i);
  }
  for (int i = 2; i <= n + 1; ++i)
    if (query(1, 1, n, 1, i - 1) > lst[i]) able[i] = 1;
  int ans = 1;
  while (able[ans] && ans <= n + 1) ++ans;
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF1436E Complicated Computations.in", "r", stdin);
  freopen("CF1436E Complicated Computations.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
